package cn.hcbycloud.auth.service.impl;

import cn.hcbycloud.auth.service.PermissionService;
import cn.hcbycloud.auth.service.RoleService;
import cn.hcbycloud.common.jwt.vo.LoginInfo;
import cn.hcbycloud.common.permission.service.PermissionCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @author gaoh
 * @desc 实现权限注解校验接口
 * @date 2022年02月02日 上午 12:34
 */
@Service("permissionCheckService")
public class PermissionCheckServiceImpl implements PermissionCheckService {
    @Autowired
    PermissionService permissionService;
    @Autowired
    RoleService roleService;
    @Override
    public List<String> getPermissions(LoginInfo loginInfo) {
        Set<String> permissionSet = permissionService.getPermissionsByUserId(loginInfo.getUserId(),
                loginInfo.getTenantId());
        List<String> result = new ArrayList<>(permissionSet);
        return result;
    }

    @Override
    public List<String> getRoles(LoginInfo loginInfo) {
        Set<String> roleSet = roleService.getRoleCodesByUserId(loginInfo.getUserId(),
                loginInfo.getTenantId());
        List<String> result = new ArrayList<>(roleSet);
        return result;
    }
}